package com.example.myapp.ADO;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.myapp.Activity.VolleyChat;
import com.example.myapp.Loading.ShapeLoadingDialog;
import com.example.myapp.Model.MsgList;
import com.example.myapp.R;
import com.example.myapp.Loading.ShapeLoadingDialog;
import com.example.myapp.Model.MsgList;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

public class MsgList_Aapter extends BaseAdapter {

    private Context context;
    private List<MsgList> chatMsgList;
    private LayoutInflater mInflater;
    private ShapeLoadingDialog shapeLoadingDialog;
    private String isUserPagecome;

    //自定义adaper开始
    public MsgList_Aapter(Context context, List<MsgList> chatMsgList) {
        this.context = context;
        this.chatMsgList = chatMsgList;
        mInflater = LayoutInflater.from(context);//初始化

    }



    @Override
    public boolean areAllItemsEnabled() {
        return super.areAllItemsEnabled();
    }

    @Override
    public int getCount() {
        return chatMsgList.size();
    }

    @Override
    public Object getItem(int i) {
        return chatMsgList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        view = mInflater.inflate(R.layout.item_listchat, null);
        CircleImageView myfrend_icon = view.findViewById(R.id.myfrend_icon);
        TextView myfrendusernmae = view.findViewById(R.id.myfrendusernmae);
        TextView myfrendjianjie = view.findViewById(R.id.myfrendjianjie);
        TextView myfrendmsgcount = view.findViewById(R.id.myfrendmsgcount);
        LinearLayout myfrendlayoutbtn= view.findViewById(R.id.myfrendlayoutbtn);
        Glide.with(context).load( chatMsgList.get(i).getIcon()).into(myfrend_icon);// CircleImageView.显示网络图片特殊方法
        myfrendusernmae.setText( ""+chatMsgList.get(i).getUsername());
        myfrendjianjie.setText(""+chatMsgList.get(i).getMsg());
        myfrendlayoutbtn.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                Intent intent = new Intent(context, VolleyChat.class);
                                intent.putExtra("userID",chatMsgList.get(i).getUserid());
                                    intent.putExtra("iconUrl",chatMsgList.get(i).getIcon());
                                    intent.putExtra("userName",chatMsgList.get(i).getUsername());
                                     intent.putExtra("isUserPagecome","MsgList");
                                context.startActivity(intent);
                            }
                        });
        if(chatMsgList.get(i).getNum()>0){
            myfrendmsgcount.setVisibility(View.VISIBLE);
            myfrendmsgcount.setText(""+chatMsgList.get(i).getNum());
        }

        return view;
    }



}
